package com.boot.controller;

import com.boot.model.User;
import com.boot.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private IUserService  userService;
    @RequestMapping("/getDemo")
    public String getDemo() {
        Map map=new HashMap();
        map.put("key","value");
        return "demo";
    }

    @RequestMapping("/getDemo1")
    public ModelAndView getDemo1(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<User> user=userService.list();
        PageInfo pageInfo = new PageInfo<>(user);
        ModelAndView view = new ModelAndView();
        view.getModel().put("page",pageInfo);

        view.setViewName("demo");
        return view;
    }
}
